# My wife often tells friends that when I walk into one of # my sections I raise the average age of people in the room # by 30 years. It is a good joke and it reflects how much # older I am than the age of the students in my class. # # Let us see how much I really do increase the average age. # First, let us set the ages of all the students. student_age <- c( 21, 19, 23, 18, 19, 20, 27, 19, 22, 20, 16, 20, 19, 33, 28, 17, 19, 20, 24, 17, 22, 26, 22, 19, 45, 20, 28, 20, 19, 21) # then we can find the average age of those students mean( student_age ) # Now we can find the ages of everyone once I enter the room all_ages <- c( student_age, 75 ) # what is the average of all 31 people? mean( all_ages ) # so I raised the average age, but only by 1.70645 years # Even for a group as small as 30 it is hard to move the # the average age by adding just one person to the room. # it might be interesting to see what happens # to the median ages median( student_age ) median( all_ages ) # In this case the median did not change at all. # let us just look at the sorted list of ages sort( all_ages ) # a different question would be "How old would I have # to be in order for me to really raise the average # age of that section by 30 years?" # We know that the average age is 22.1 and we get that # by dividing the sum of the ages by the number of # students. sum( student_age ) length( student_age ) 663/30 # Now, if I want to add one person, so we will have # 31 people, and I want to have the average of the 31 # people be 22.1+30 = 52.1 then the sum of the 31 ages # will have to be 31*52.1 31*52.1 # But the sum of the 30 student ages is only 663. # So, my age would have to be 1615.1- 663 1615.1-663 # Thus, If I were 952.1 years old, and I know that may # seem correct given my appearance, then when I walk into # the room I would raise the average age by 30 years! new_ages <- c(student_age, 952.1) mean( new_ages )